package com.hl.sfzy.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hl.sfzy.constant.CommonConstant;
import com.hl.sfzy.entity.Knowledge;
import com.hl.sfzy.entity.Psychometric;
import com.hl.sfzy.mapper.PsychometricMapper;
import com.hl.sfzy.service.PsychometricService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 1. @ClassDescription:
 * 2. @ClassName Psychometric
 * 3. @Description TODO
 * 4. @Author: YuKunXu
 * 5. @Date: 2024年01月12日 10:31
 * 6. @Project: sfzy
 * 7. @Version 1.0
 */
@Service
public class PsychometricServiceImpl implements PsychometricService {
    @Autowired
    private PsychometricMapper psychometricMapper;

    @Override
    public void add(Psychometric entity) throws Exception {
        psychometricMapper.insert(entity);
    }

    @Override
    public void edit(Psychometric entity) {
        psychometricMapper.update(entity);
    }

    @Override
    public void remove(Integer id) {
        psychometricMapper.delete(id);
    }

    @Override
    public void removeBatch(Integer[] ids) {
        psychometricMapper.deleteBatch(ids);
    }

    @Override
    public List<Psychometric> find(Psychometric entity) {
        return psychometricMapper.select(entity);
    }

    @Override
    public Map<String, Object> findPage(Integer pageNum, Integer pageSize, Psychometric entity) {
        //分页业务实现
        PageHelper.startPage(pageNum, pageSize);

        List<Psychometric> list = psychometricMapper.select(entity); // 当前页数据

        PageInfo<Psychometric> pageInfo = new PageInfo<>(list); // 分页信息对象

        /*
         * 把前台需要的数据反馈
         * 1、当前页面数据（数据列表）
         * 2、此次查询的总记录数
         */
        Map<String, Object> pageMap = new HashMap<>();
        pageMap.put(CommonConstant.PAGE_LIST, list);
        pageMap.put(CommonConstant.PAGE_TOTAL, pageInfo.getTotal());

        return pageMap;
    }

    @Override
    public Psychometric findById(Integer id) {
        return psychometricMapper.selectById(id);
    }
}